<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    /*
        post API
        为此，第一步需要把 Content- Type 头部设置为"application/x-www-formurlencoded"，这是提交表单时使用的内容类型
     */

    function submitData() {
        const url = "http://47.106.187.222/message/message"
        let obj = {userId: 22, message: "我是用来测试api的"}
        let xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
                    console.log(xhr.responseText);
                } else {
                    console.log("Request was unsuccessful: " + xhr.status);
                }
            }
        };
        xhr.open("post", url, true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        // 如果要发送数据的话,需要序列化 不知道如何处理
        // xhr.send(JSON.stringify(obj));
        // xhr.send(null);
    }

    submitData();


</script>
</body>
</html>